<?php

namespace Modules\SmallApi\Http\Controllers;

use HiCommon\Service\UsersVehicleService;
use HiCommon\Service\VehicleModelService;
use Illuminate\Support\Facades\Request;

class UserVehicleController extends BaseController
{

    /**
     * 车型列表-顶级-new
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function vehicle_model_top_list(){
        try {
            $n_pid = intval(Request::input('pid'));
            $res = VehicleModelService::api_vehicle_model_top_list($n_pid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 车型列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function vehicle_model_list(){
        try {
            $n_pid = intval(Request::input('pid'));
            $res = VehicleModelService::api_vehicle_model_list($n_pid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 用户车辆档案列表
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function users_vehicle_list()
    {
        try {
            $n_uid = (int)small_api_user_id();
            return UsersVehicleService::api_user_vehicle_list($n_uid);
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 添加用户车辆档案
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function add_users_vehicle()
    {
        try {
            $n_uid = (int)small_api_user_id();
            $arr_input = Request::input();
            shiwu_start();
            $arr_input['users_company_id'] = 0;
            $res = UsersVehicleService::api_add_whole_user_vehicle($n_uid,$arr_input);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 修改用户车辆档案
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_users_vehicle()
    {
        try {
            $n_uid = (int)small_api_user_id();
            $arr_input = Request::input();
            return UsersVehicleService::api_edit_whole_user_vehicle($n_uid,$arr_input);
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }



    /**
     * 删除用户车辆档案
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function del_users_vehicle()
    {
        try {
            $n_uid = (int)small_api_user_id();
            $n_id = intval(Request::input('id',0));
            return UsersVehicleService::api_del_user_vehicle($n_id,$n_uid);
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 设置用户默认车辆
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function set_default_user_vehicle(){
        try {
            $n_uid = api_user_id();
            $n_id = Request::input('id',0);

            shiwu_start();
            $res = UsersVehicleService::api_set_default_user_vehicle($n_id,$n_uid);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }



}